package com.cloud.consumer;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.naming.NamingService;
import com.cloud.consumer.feign.ConsumerFeignClient;
import com.fasterxml.jackson.databind.ObjectMapper;
import jdk.nashorn.internal.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.sql.SQLOutput;

/**
 * @ClassName: NacosConsumer
 * @Author: wl
 * @Date: 2021/11/17 14:49
 * @Description: TODO
 */
@RestController
public class NacosConsumer {

    private static final String PROVIDER_SERVER = "http://nacos-provider";

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private DiscoveryClient discoveryClient;

    @Resource
    ConsumerFeignClient consumerFeignClient;

    @RequestMapping("/hello")
    public String hello() {
        System.out.println(discoveryClient.getServices());
        return "consumer[ " + restTemplate.getForObject(PROVIDER_SERVER+"/hello", String.class) + " ]";

    }

    @RequestMapping("/feign")
    public String feign() {
        return "consumer feign[ " + consumerFeignClient.hello() + "]";

    }

}
